
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="/plan/caigou/css/add.css"/>
    <script type="text/javascript" src="/plan/caigou/js/jquery.1.9.1.js" ></script>
    <script type="text/javascript" src="/plan/caigou/js/layer.js" ></script>
    <link rel="stylesheet" type="text/css" href="/plan/caigou/css/layer.css"/>
    <script type="text/javascript" src="/plan/caigou/js/iScroll.js" ></script>
    <script type="text/javascript" src="/plan/caigou/js/Mdate.js" ></script>
    <link rel="stylesheet" href="/plan/caigou/css/Mdate.css" />
    <script type="text/javascript" src="/plan/caigou/js/rem.js" ></script>
    <title>新增供应商</title>
</head>
<style type="text/css">
    .pay{width: 100%;height: 0.98rem;line-height: 0.98rem;}
    #mapPage{
        position: absolute;;
        top:0;
        left: 0;
        width: 100%;
        height: 100%;
        display: none;
        z-index: 100000;
    }
    iframe{border: 0}
</style>
<body>
<section id="sup1">
    <ul class="order_money" style="padding: 0 0.3rem;background: #fff;">
        <li>
            <span class="chang">供应商名称</span>
            <input type="text" name="" id="storename" value="" data="bianhao111">
            <span class="bitian">必填</span>
        </li>
        <li>
            <span class="num">供应商编号</span>
            <input type="text" name="" id="week" value="{$bh}">
        </li>
        <li style="min-height: 1.5rem;position: relative" class="caigou">
            <span class="address">地址</span>
            <span class="jt" style="position: absolute;right: 0"></span>

            <span id="address" cols="2"  placeholder="请输入地址" style="cursor: pointer;width: 100%;display: inline-block;min-height: .4rem; ">123213</span>
            <input type="hidden" name="" id="lat" value="">
            <input type="hidden" name="" id="cityname" value="">
        </li>
        <li style="overflow: hidden;">
            <span class="address">详细地址</span>
            <input id="address1" placeholder="精确到门牌号">

        </li>




    </ul>
    <div class="contact">联系人信息</div>
    <ul class="beizhu">
        <li>
            <span class="chang">姓名</span>
            <input type="text" name="" id="lxr" value="">
            <span class="bitian">必填</span>
        </li>
        <li>
            <span class="money">手机号</span>
            <input type="number" name="" id="mobile" value="" placeholder="请输入手机号">
        </li>
        <li style="height: 2.3rem;">
            <p class="title">单据备注</p>
            <textarea class="bei" id="mark" style="height: 1.3rem;"></textarea>
        </li>
    </ul>
    <div class="button">
        <input class="pay" type="button" name="" id="submit" value="保存">
    </div>
</section>
<iframe id="mapPage" width="100%" height="100%" scrolling="no" frameborder=0>
</iframe>
<script>//提交表单
window.addEventListener('message',function (event) {
    var loc = event.data;

    if(loc && loc.module=='locationPicker'){
        $("#address").html(loc.poiaddress);

        $("#lat").val(loc.latlng.lat+','+loc.latlng.lng);
        $("#cityname").val(loc.cityname);
        $("#pro1").show();
        $("#mapPage").hide();
    }

},false);

$(function () {
    $("#submit").click(function () {
        if ($("#submit").hasClass("disabled")) return false;

        if ($("#storename").val()==''){
            layer.open({
                content:'请输入供应商名称' ,
                skin: 'msg',
                time: 2 //2秒后自动关闭
            });
            return false;
        }
        if ($("#address").html()=='') {
            layer.open({
                content:'请输入供应商名称' ,
                skin: 'msg',
                time: 2 //2秒后自动关闭
            });
            return false;
        }
        if ($("#lxr").val()=='') {
            layer.open({
                content:'请输入联系人姓名' ,
                skin: 'msg',
                time: 2 //2秒后自动关闭
            });
            return false;
        }
        if (!(/^1[3456789]\d{9}$/.test($("#mobile").val()))) {
            layer.open({
                content:'手机格式错误' ,
                skin: 'msg',
                time: 2 //2秒后自动关闭
            });
            return false;
        }
        $("#submit").addClass("disabled");

        $.ajax({
            type:"post",
            url:"/index/store/add_supplier",
            data:{sname:$("#storename").val(),b_n:$("#week").val(),lxr:$("#lxr").val(),
                mobile:$("#mobile").val(),address:$("#address").html(),address1:$("#address1").val(),
                lat:$("#lat").val(),
                cityname:$("#cityname").val()
            },
            success:function (data) {

                layer.closeAll();

                if (data.code==1){

                    layer.open({
                        content:'操作成功' ,
                        skin: 'msg',
                        time: 2 //2秒后自动关闭
                    });
                    setTimeout(function () {
                        location.href="/index/store/cgadd";
                    },200);
                } else{
                    layer.open({
                        content:''+data.msg+'' ,
                        skin: 'msg',
                        time: 2 //2秒后自动关闭
                    });
                    setTimeout(function () {
                        location.reload();
                    },800);
                }

            }

        })

    })
    $("#address").click(function () {
        if ($("#mapPage").hasClass('isload')) {
            $("#pro1").hide();
            $("#mapPage").show();
            return false;
        }
        layer.open({type: 2, shadeClose: false});
        $(this).blur();//移除光标
        $("#mapPage").attr("src","https://apis.map.qq.com/tools/locpicker?search=1&type=1&policy=1&key=4HZBZ-DPUKX-T2S4B-TQVCQ-RJ6MK-YRFDW&referer=myapp");
        $("#mapPage").load(function () {
           $(this).addClass("isload");
           layer.closeAll();//加载成功，移除
            $("#pro1").hide();
            $("#mapPage").show();
        })

    })
})

</script>

</body>
</html>
